package com.cheng.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

//该类可以捕获全部类产生的异常
@ControllerAdvice
public class TryCatch {
    @ExceptionHandler({ArithmeticException.class,ArrayIndexOutOfBoundsException.class}/*那个捕获类路劲（本身或者基类，本身短）最短哪个捕获*/)//可指定捕获什么异常
    //springmvc处理异常需要单独一个类  该类会捕获其他方法出现的异常
    public ModelAndView handlerArithmeticException(Exception e){
        System.out.println(e);
        ModelAndView mv=new ModelAndView("error");
        mv.addObject("er",e);
        return mv;
    }
}
